<html>
<head><meta charset="utf-8"><title>Clippy started panicking on optimized_mir call · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html">Clippy started panicking on optimized_mir call</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222703534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222703534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222703534">(Jan 14 2021 at 11:03)</a>:</h4>
<p>Did something change with the <code>optimized_mir</code> query recently? Between nightlies 2021-01-02 and 2021-01-14</p>
<p>Clippy started panicking on a query call to <a href="https://github.com/rust-lang/rust-clippy/blob/00586dfdcd10c37cb8b132c72ed0558304955042/clippy_lints/src/implicit_return.rs#L136"><code>cx.tcx.optimized_mir()</code></a>  on a function body. The panic comes from <code>get_optimized_mir</code> inside <a href="https://github.com/rust-lang/rust/blob/c7b0ddbffebee1cb06f184e815ca637706c53053/compiler/rustc_metadata/src/rmeta/decoder.rs#L1189"><code>compiler/rustc_metadata/src/rmeta/decoder.rs</code></a>, which suggests, that the MIR query fails to save/recover the MIR of a function.</p>
<p>Steps to reproduce:</p>
<ol>
<li>Compile this pull request of Clippy: <a href="https://github.com/rust-lang/rust-clippy/issues/6586">clippy#6586</a> <code>cargo install --path . --debug --force</code></li>
<li><code>cp ~/.cargo/bin/*clippy* $(rustc +nightly-2021-01-14 --print sysroot)/bin</code></li>
<li>Clone <a href="https://github.com/Marwes/combine">https://github.com/Marwes/combine</a></li>
<li>Check it with Clippy: </li>
</ol>
<div class="codehilite"><pre><span></span><code>RUST_BACKTRACE=full LD_LIBRARY_PATH=$(rustc +nightly-2021-01-14 --print sysroot)/lib cargo +nightly-2021-01-14 clippy --all-targets --all-features
</code></pre></div>



<a name="222703616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222703616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222703616">(Jan 14 2021 at 11:04)</a>:</h4>
<p>Miri is no longer encoded by default in check mode.</p>



<a name="222703653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222703653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222703653">(Jan 14 2021 at 11:04)</a>:</h4>
<p>This is <a href="https://github.com/rust-lang/rust/issues/80718">#80718</a></p>



<a name="222704052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222704052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222704052">(Jan 14 2021 at 11:09)</a>:</h4>
<p>So should I set the <code>always_encode_mir</code> option for Clippy until someone who knows what they do comes and properly fixes this? This would mean, that we can never call <code>optimized_mir</code> on closures in Clippy?</p>



<a name="222704410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222704410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222704410">(Jan 14 2021 at 11:12)</a>:</h4>
<p>Can't this be fixed by getting the function signature like at <a href="https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301">https://github.com/rust-lang/rust/blob/f52c72948aa1dd718cc1f168d21c91c584c0a662/src/librustc_middle/ty/layout.rs#L2301</a>?</p>



<a name="222704433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222704433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222704433">(Jan 14 2021 at 11:12)</a>:</h4>
<p>If not, then <code>-Zalways-encode-mir</code> should fix it for now.</p>



<a name="222706382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222706382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222706382">(Jan 14 2021 at 11:36)</a>:</h4>
<p>Hm, this function is private and it seems that is for a reason.</p>



<a name="222720259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222720259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222720259">(Jan 14 2021 at 14:02)</a>:</h4>
<p>After trying to fix that for some time now, I've come to the conclusion, that I have to add <code>-Zalways-encode-mir</code>. This broke Clippy in every case where Clippy is trying to access MIR. I think we should get rid of calls to the <code>optimized_mir</code> query, like suggested before.</p>



<a name="222720434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222720434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222720434">(Jan 14 2021 at 14:04)</a>:</h4>
<p>If you only query optimized_mir for the local crate then it should be fixed by <a href="https://github.com/rust-lang/rust/issues/81003">#81003</a>.</p>



<a name="222720500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222720500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222720500">(Jan 14 2021 at 14:04)</a>:</h4>
<p>That PR will only encode optimized_mir for generators.</p>



<a name="222720615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222720615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222720615">(Jan 14 2021 at 14:05)</a>:</h4>
<p>cargo check doesn't include optimized mir for most items since 2018</p>



<a name="222720800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222720800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222720800">(Jan 14 2021 at 14:07)</a>:</h4>
<p>I can try if that PR fixes it. But I doubt it, since adding the option to just the compiled crate and not the deps didn't fix the problem.</p>



<a name="222721032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222721032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222721032">(Jan 14 2021 at 14:09)</a>:</h4>
<p>If you could test if this PR fixes the issue that would be great.</p>



<a name="222721113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222721113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222721113">(Jan 14 2021 at 14:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call/near/222703616">said</a>:</p>
<blockquote>
<p>Miri is no longer encoded by default in check mode.</p>
</blockquote>
<p>I think this might be why <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/What.20does.20this.20compile.20error.20mean.3F">https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/What.20does.20this.20compile.20error.20mean.3F</a> was breaking :D let me try <code>-Z always-encode-mir</code> there</p>



<a name="222721772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222721772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222721772">(Jan 14 2021 at 14:14)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> generators are special because it should be the only thing where optimized mir is required for non-local crate, even if you never request it directly (assuming no codegen).</p>



<a name="222725303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222725303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222725303">(Jan 14 2021 at 14:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="264664">flip1995</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call/near/222720800">said</a>:</p>
<blockquote>
<p>I can try if that PR fixes it. But I doubt it, since adding the option to just the compiled crate and not the deps didn't fix the problem.</p>
</blockquote>
<p>^^ It would be also the reason why adding -Zencode-mir to the crate, without adding it to the deps didn't fix the problem.</p>



<a name="222726471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222726471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222726471">(Jan 14 2021 at 14:48)</a>:</h4>
<p>Yes that fixed it! Thanks <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span></p>



<a name="222735672"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222735672" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222735672">(Jan 14 2021 at 15:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call/near/222721113">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call/near/222703616">said</a>:</p>
<blockquote>
<p>Miri is no longer encoded by default in check mode.</p>
</blockquote>
<p>I think this might be why <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/What.20does.20this.20compile.20error.20mean.3F">https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/What.20does.20this.20compile.20error.20mean.3F</a> was breaking :D let me try <code>-Z always-encode-mir</code> there</p>
</blockquote>
<p>nope :(</p>
<div class="codehilite"><pre><span></span><code>error: crate `std` required to be available in rlib format, but was not found in this form
</code></pre></div>



<a name="222735721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/Clippy%20started%20panicking%20on%20optimized_mir%20call/near/222735721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/Clippy.20started.20panicking.20on.20optimized_mir.20call.html#222735721">(Jan 14 2021 at 15:47)</a>:</h4>
<p>well, probably unrelated to this change then</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>